using System;
using System.Runtime.Serialization;

using BLToolkit.Mapping;

using TrueCode.Core.Aspects;
using TrueCode.Core.EditableEntity;
using TrueCode.Core.Validation;


namespace EMan.Common.EnterpriseStructure
{
  [DataContract]
  public class Job : Entity< Job >
  {
    private static int _idgen = -1;

    public Job( string name, string description = null ) : this( Guid.NewGuid(), _idgen--, name, description, 0 ){}
    private Job( Guid key, int id, string name, string description, int revision )
    {
      Key = key;
      Id = id;
      Title = name;
      Description = description;
      Revision = revision;
    }


    [DataMember]
    [Trimmable]
    [Validate.NotEmpty, Validate.MaxLength( 50 )]
    [Editable(EditableMode.ReadWrite)]
    public string Title{ get; set; }

    [DataMember]
    [NullValue( null )]
    [Validate.MaxLength( 500 )]
    [Editable(EditableMode.ReadWrite)]
    public string Description{ get; set; }

    public Job Copy()
    {
      return new Job( Key, Id, Title, Description, Revision );
    }

    #region BLT
    [Obsolete("Do not use this constructor, it is for BLT only"), UsedImplicitly]
    public Job() : this( Guid.NewGuid(), int.MinValue, "Created by BLT", null, int.MinValue ){}
    #endregion
  }
}